package datastructure.ch05_queues.ch04_linked_queue;

import datastructure.ch03_linked.ch10_double_linkedlist.DoubleLinkedList;
import datastructure.ch05_queues.ch02_interface_abstarct.Queue;

/**
 * 
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
public class LinkedQueue<E> implements Queue<E> {
    public static void main(String[] args) {
        LinkedQueue<Integer> data = new LinkedQueue<>();
        data.enqueue(1);
        data.enqueue(2);
        data.enqueue(3);
        data.enqueue(4);
        System.out.println(data.dequeue());
        System.out.println(data.getFront());
    }
    DoubleLinkedList<E> linkedList;

    public LinkedQueue() {
        linkedList = new DoubleLinkedList<>();
    }

    @Override
    public int getSize() {
        return linkedList.size();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    @Override
    public void clear() {
        linkedList.clear();
    }

    @Override
    public void enqueue(E e) {
        linkedList.add(e);
    }

    @Override
    public E dequeue() {
        return linkedList.remove(0);
    }

    @Override
    public E getFront() {
        return linkedList.get(0);
    }
}
